<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
%>

<div class="row">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading header">
                <h3 class="panel-title" id="title">会议安排登记表</h3>
            </div>

            <!-- BASIC FORM ELEMENTS -->
            <!--===================================================-->
            <form id="form_meeting_input" class="panel-body form-horizontal form-padding">
                <input type="hidden" name="keyId" id="keyId" value="${meeting.id}" />
                <input type="hidden" name="curDutyId" id="curDutyId" value=""/>

                <div class="form-group">
                    <label class="col-md-2 control-label">是否外出会议<i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">

                        <div class="radio">
                            <!-- Inline radio buttons -->
                            <input type="radio" name="isOut" id="isOut1Selected" class="magic-radio" value="1"
                            <c:if test="${meeting.isOut==1}"> checked="checked"</c:if> >
                            <label for="isOut1Selected">是</label>

                            <input type="radio" name="isOut" id="isOut2Selected" class="magic-radio" value="0"
                            <c:if test="${meeting.isOut==0}"> checked="checked"</c:if> >
                            <label for="isOut2Selected">否</label>

                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">日程公开<i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">

                        <div class="radio">
                            <!-- Inline radio buttons -->
                            <input type="radio" name="isPublic" id="isPublic1Selected" class="magic-radio" value="1"
                            <c:if test="${meeting.isPublic==1}"> checked="checked"</c:if> >
                            <label for="isPublic1Selected">是</label>

                            <input type="radio" name="isPublic" id="isPublic2Selected" class="magic-radio" value="0"
                            <c:if test="${meeting.isPublic==0}"> checked="checked"</c:if> >
                            <label for="isPublic2Selected">否</label>

                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">会议名称<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="name" name="name" class="form-control" placeholder="请输入会议名称" value="${meeting.name}">
                    </div>
                </div>

                <div class="form-group div-Hidden">
                    <label class="col-md-2 control-label">开始日期<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-2">
                        <div class="input-group date">
                            <input type="text" class="form-control" id="datStart" name="datStart" placeholder="请选择开始日期"
                                   value=<fmt:formatDate pattern="yyyy-MM-dd" value="${meeting.datStart}" /> >
                            <span class="input-group-addon"><i class="ti-calendar"></i></span>
                        </div>
                    </div>
                    <label class="col-md-2 control-label">开始时间<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-2">
                        <div class="input-group clockpicker">
                            <input type="text" class="form-control" id="timStart" name="timStart" placeholder="请选择开始时间"
                                   value=<fmt:formatDate pattern="HH:mm" value="${meeting.timStart}" /> >
                            <span class="input-group-addon"><i class="ti-alarm-clock"></i></span>
                        </div>
                    </div>
                </div>

                <div class="form-group div-Hidden">
                    <label class="col-md-2 control-label">结束日期<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-2">
                        <div class="input-group date">
                            <input type="text" class="form-control" id="datEnd" name="datEnd" placeholder="请选择结束日期"
                                   value=<fmt:formatDate pattern="yyyy-MM-dd" value="${meeting.datEnd}" /> >
                            <span class="input-group-addon"><i class="ti-calendar"></i></span>
                        </div>
                    </div>
                    <label class="col-md-2 control-label">结束时间<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-2">
                        <div class="input-group clockpicker">
                            <input type="text" class="form-control" id="timEnd" name="timEnd" placeholder="请选择结束时间"
                                   value=<fmt:formatDate pattern="HH:mm" value="${meeting.timEnd}" /> >
                            <span class="input-group-addon"><i class="ti-alarm-clock"></i></span>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">会议议题<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="subject" name="subject" class="form-control" placeholder="请输入会议议题" value="${meeting.subject}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        <a href="javascript:void(0);" onclick="fn_member_dialog_select()" style="color: #0a6dbd">会议负责人</a>
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="userName" name="userName" class="form-control" placeholder="请选择会议负责人" value="${meeting==null?user.name:meeting.chief.name}">
                        <input type="hidden" id="userId" name="userId" value="${meeting==null?user.id:meeting.chief.id}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        <a href="javascript:void(0);" onclick="fn_members_dialog_select()" style="color: #0a6dbd">内部参会人员</a>
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="userNames" name="userNames" class="form-control" placeholder="请选择内部参会人员"
                               value="<c:forEach var="item" items="${meeting.participants}" varStatus="status">${item.name}<c:if test="${!status.last}">,</c:if></c:forEach>">
                        <input type="hidden" id="userIds" name="userIds"
                               value="<c:forEach var="item" items="${meeting.participants}" varStatus="status">${item.id}<c:if test="${!status.last}">,</c:if></c:forEach>">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">外部参会人员</label>
                    <div class="col-md-6">
                        <input type="text" id="outermen" name="outermen" class="form-control" placeholder="请输入外部参会人员" value="${meeting.outermen}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">具体地点<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="address" name="address" class="form-control" placeholder="请输入具体地点" value="${meeting.address}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">会议辅助设备
                        <span style="display: none" id="aidSetsSpan">${meeting.aidSets}</span>
                    </label>
                    <div class="col-md-6">

                        <div class="checkbox">
                            <!-- Inline checkbox buttons -->
                            <input type="checkbox" name="aidSets" id="aidSets1Selected" class="magic-checkbox" value="01"
                            <c:if test="${meeting.aidSets.indexOf('01')>-1}"> checked="checked"</c:if> >
                            <label for="aidSets1Selected">电脑</label>

                            <input type="checkbox" name="aidSets" id="aidSets2Selected" class="magic-checkbox" value="02"
                            <c:if test="${meeting.aidSets.indexOf('02')>-1}"> checked="checked"</c:if> >
                            <label for="aidSets2Selected">投影仪</label>

                            <input type="checkbox" name="aidSets" id="aidSets3Selected" class="magic-checkbox" value="03"
                            <c:if test="${meeting.aidSets.indexOf('03')>-1}"> checked="checked"</c:if> >
                            <label for="aidSets3Selected">激光笔</label>

                            <input type="checkbox" name="aidSets" id="aidSets4Selected" class="magic-checkbox" value="04"
                            <c:if test="${meeting.aidSets.indexOf('04')>-1}"> checked="checked"</c:if> >
                            <label for="aidSets4Selected">白板</label>

                            <input type="checkbox" name="aidSets" id="aidSets5Selected" class="magic-checkbox" value="05"
                            <c:if test="${meeting.aidSets.indexOf('05')>-1}"> checked="checked"</c:if> >
                            <label for="aidSets5Selected">话筒音响</label>

                            <input type="checkbox" name="aidSets" id="aidSets6Selected" class="magic-checkbox" value="06"
                            <c:if test="${meeting.aidSets.indexOf('06')>-1}"> checked="checked"</c:if> >
                            <label for="aidSets6Selected">人名牌</label>

                            <input type="checkbox" name="aidSets" id="aidSets7Selected" class="magic-checkbox" value="07"
                            <c:if test="${meeting.aidSets.indexOf('07')>-1}"> checked="checked"</c:if> >
                            <label for="aidSets7Selected">其他</label>

                        </div>
                    </div>
                </div>

                <div class="form-group" id="otherSetDiv">
                    <label class="col-md-2 control-label">其他辅助设备<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="otherSet" name="otherSet" class="form-control" placeholder="请输入其他辅助设备" value="${meeting.otherSet}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">提交人</label>
                    <div class="col-md-2">
                        <p class="form-control-static">${meeting.creater.name}</p>
                    </div>
                    <label class="col-md-2 control-label">提交日期</label>
                    <div class="col-md-2">
                        <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${meeting.dateApply}" /></p>
                    </div>
                </div>

                <div class="panel-footer">
                    <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
                        <i class="fa fa-lg fa-mail-reply"></i> 返回
                    </a>
                    <a class="btn btn-success" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存 </a>
                    <c:if test="${meeting==null || meeting.processState=='Draft'}">
                        <a class="btn btn-warning" id="btn-commit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交 </a>
                    </c:if>
                    <c:if test="${meeting!=null && meeting.processState=='Backed'}">
                        <a class="btn btn-warning" id="btn-recommit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 再提交 </a>
                    </c:if>
                    <c:if test="${meeting.numStatus==1 && user.id==meeting.creater.id && meet==1}">
                        <a class="btn btn-success" id="btn-update-common" href="javascript:void(0);"><i class="fa fa-lg fa-edit"></i> 完成修改 </a>
                    </c:if>
                </div>
                
            </form>
            <!--===================================================-->
            <!-- END BASIC FORM ELEMENTS -->
            
        </div>
    </div>
</div>

<script>
    var index = "${index}";
    var todo = "${todo}";
    var remind = "${remind}";
    var record = "${record}";
    var draft =  "${draft}";

    $(function(){
        var pdata= {
            keyId:$("#keyId1").val(),
            entityName:"com.fz.us.oa.core.entity.com.Meeting"
        };
        multiDuty(pdata);
    });

    // 日期选择
    $('.input-group.date').datepicker({
        format: 'yyyy-mm-dd',
        weekStart: 1,
        autoclose: true,
        todayBtn: 'linked',
        todayHighlight: true,
        language: 'zh-CN'
    });

    // 时间选择
    $('.clockpicker').clockpicker({
        autoclose: true,
        default: 'now'
    });

    function fn_member_dialog_select() {
        __open_dialog_select('选择成员', '<%=path%>/main/member/dialog', function (dialogRef) {
            var callback = function (data) {
                if (data) {
                    dialogRef.close();

                    // 获取 user
                    $('#userId').val(data.id);
                    $('#userName').val(data.name)
                } else {
                    dialogRef.enableButtons();
                }
            };
            fn_dialog_member_select(callback);
        });
    }

    function fn_members_dialog_select() {
        __open_dialog_select('选择成员', '<%=path%>/main/member/dialogs?sids='+$("#userIds").val(), function (dialogRef) {
            var callback = function (data) {
                if (data) {
                    dialogRef.close();

                    // 获取 user
                    $('#userIds').val(data.ids);
                    $('#userNames').val(data.names)
                } else {
                    dialogRef.enableButtons();
                }
            };
            fn_dialog_members_select(callback);
        });
    }

    //校验
    function infoValidate() {
        var tmp = "";
        tmp = $("input#name").val();
        if(!tmp){
            __toastr_error("请输入会议名称！");
            return false;
        }

        tmp = $("input#datStart").val();
        if(!tmp){
            __toastr_error("请选择开始日期！");
            return false;
        }

        tmp = $("input#timStart").val();
        if(!tmp){
            __toastr_error("请选择开始时间！");
            return false;
        }

        tmp = $("input#datEnd").val();
        if(!tmp){
            __toastr_error("请选择结束日期！");
            return false;
        }

        tmp = $("input#timEnd").val();
        if(!tmp){
            __toastr_error("请选择结束时间！");
            return false;
        }

        tmp = $("input#subject").val();
        if(!tmp){
            __toastr_error("请输入会议议题！");
            return false;
        }

        tmp = $("input#userName").val();
        if(!tmp){
            __toastr_error("请选择会议负责人！");
            return false;
        }

        tmp = $("input#userNames").val();
        if(!tmp){
            __toastr_error("请选择内部参会人员！");
            return false;
        }

        tmp = $("input#address").val();
        if(!tmp){
            __toastr_error("请输入会议地点！");
            return false;
        }

        if($("#aidSets7Selected").prop("checked")){
            tmp = $("input#otherSet").val();
            if(!tmp){
                __toastr_error("请输入其他辅助设备！");
                return false;
            }
        }
        
        return true;
    }

    //保存
    $("#btn-save-common").click(
            function(e) {
                __confirm_dialog("提示：","确定保存吗？",
                        function () {
                            __form_save("form_meeting_input", "<%=path%>/com/meeting/save",function(){
                                $("#apply-re-common").trigger("click");
                                $('#calendar').fullCalendar('refetchEvents');
                            });
                        }
                )
            }
    );

    //提交
    $("#btn-commit-common,#btn-recommit-common").click(
            function(e) {
                var $valid = infoValidate();
                if(!$valid) return false;

                __confirm_dialog("提示：","请确认是否进行提交？",
                        function () {
                            __form_save("form_meeting_input", "<%=path%>/com/meeting/commit",function() {
                                $("#apply-re-common").trigger("click");
                                $('#calendar').fullCalendar('refetchEvents');
                            });
                        }
                )
            }
    );

    // 完成修改
    $("#btn-update-common").click(
        function(e) {
            var $valid = infoValidate();
            if(!$valid) return false;

            __confirm_dialog("提示：","请确认是否完成修改？",
                function () {
                    __form_save("form_meeting_input", "<%=path%>/com/meeting/update",function() {
                        $("#apply-re-common").trigger("click");
                        $('#calendar').fullCalendar('refetchEvents');
                    });
                }
            )
        }
    );

            //返回视图
            $("#apply-re-common").click(function(){
                if(index==1){
                    loadURL("menu/dashboard",$('#page-content'));
                }else if(todo==1){
                    loadURL("menu/toDo",$('#page-content'));
                }else if(remind==1){
                    loadURL("menu/remind",$('#page-content'));
                }else if(record==1){
                    loadURL("menu/taskRecord?type=1",$('#page-content'));
                }else if(record==2){
                    loadURL("menu/taskRecord?type=2",$('#page-content'));
                }else if(draft==1){
                    loadURL("menu/draft",$('#page-content'));
                }else{
                    returnToHashUrl()
                }
            });

    // 加载完成后执行
    $(function(){
        $("#aidSets7Selected").click(function(){
            if($(this).prop("checked")){
                $("#otherSetDiv").show();
            } else {
                $("#otherSetDiv").hide();
            }
        });

        var aidSets = $("#aidSetsSpan").text();
        if(aidSets.indexOf("07")>-1){
            $("#otherSetDiv").show();
        } else {
            $("#otherSetDiv").hide();
        }
    })

</script>




